home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5066 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  55 lines

  1. Path: prairienet.org!wemccaug
  2. From: wemccaug@prairienet.org (Wendy E. McCaughrin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: "new" creams data structure -- why?
  5. Date: 2 Feb 1996 11:51:43 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4estsf$2v@vixen.cso.uiuc.edu>
  8. References: <4erl1i$oas@news1.usa.pipeline.com>
  9. Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
  10. NNTP-Posting-Host: firefly.prairienet.org
  11.  
  12.  
  13. In a previous article, grantp@usa.pipeline.com (Pete) says:
  14.  
  15. >On Feb 01, 1996 23:08:16 in article <"new" creams data structure -- why?>,
  16. >'<73067.3334@compuserve.com>' wrote: 
  17. >> 
  18. >>dear experts:  why would the following line alloc memory where there is 
  19. >>insufficient space for it?  when i memcpy to clear the string, it wipes
  20. >out 
  21. >>a data structure i needed.  the line is 
  22. >> 
  23. >>char* somestring = new char [300]; 
  24. >> 
  25. >>when it's my fault i can deal with it, but how do i prevent this?  or is
  26. >it 
  27. >>a scoping problem or something? 
  28. >> 
  29. >>many thanks for any ideas. 
  30. >If operator new fails -- assuming it's the default 
  31. >global one -- it returns 0.  If you don't test for it, then it's 
  32. >your fault.  But I suspect the problem is elsewhere. 
  33.  All true, but then this is why _new_handler exists: to point to your
  34.  'new' handler if you're not happy with the default one. Just say:
  35.      set_new_handler(my_new_handler); 
  36.  where 'my_new_handler' is your cunstomized function to output diagnostics
  37.  when it gets invoked by 'new' upon exhaustion of available memory. Either
  38.  by using #include's or declaring yourself, you must have:
  39.  
  40.   typedef void (*FP)();   // function-ptr type, FP
  41.  
  42.   extern FP set_new_handler(FP);
  43.  
  44.   and your routine should be prototyped:  void my_new_handler();
  45.  
  46.   FInally, your diagnostic routine should have access (via globals, e.g.)
  47.  to the variables you want to diagnose.
  48.  
  49.  -- Scott
  50.  
  51.